/*
        Firesoft 
        
    Copyright (C) 2010, Arttu Viljakainen 
    Published under GNU General Public License V3 
    (see http://www.gnu.org/licenses/licenses.html)
    
    This file is part of Firesoft.

    Firesoft is free software: 
    you can redistribute it and/or modify it under the terms of the GNU General 
    Public License as published by the Free Software Foundation, 
    either version 3 of the License, or (at your option) any later version.

    Firesoft is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 
    Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tool for Path Finding Algorithm Testing. If not, see         
    <http://www.gnu.org/licenses/>.
 */
package softstarter.functionality;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JDialog;

import softstarter.gui.SoftStarter;

import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.JIntellitype;


public class FireActionsListener implements ActionListener, HotkeyListener, KeyListener {

	private ControllerInterface controller;
	private SoftStarter host; // Interface...
	private JDialog settingsDialog;
	
	public FireActionsListener(ControllerInterface controller, SoftStarter host) {
		this.controller = controller;
		this.host = host;
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		if(e.getActionCommand().equals("Go")) {
			controller.performAction();
		} else if(e.getActionCommand().equals("Show files")) {
			host.showFileList();
		} else if(e.getActionCommand().equals("Hide files")) {
			host.hideFileList();
		} else if(e.getActionCommand().equals("Exit")) {
			JIntellitype.getInstance().cleanUp();
			System.exit(0);
		}
		
	}

	@Override
	public void onHotKey(int arg0) {
		System.out.println("Hotkey pressed!");
		if(host.isVisible())
			host.setVisible(false);
		else
			host.setVisible(true);		
	}

	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent event) {
		
		if((int)event.getKeyChar() == 10) { // Enter
			controller.performAction();
		} else {
			controller.populateProspectList(controller.getHost().getCommandLine().getEditor().getItem().toString() + event.getKeyChar());
		}
		
	}

}
